package com.zbkj.crmeb.merchant.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.store.model.ActivityManage;
import com.zbkj.crmeb.store.request.ActivityProductEnrollRequest;
import com.zbkj.crmeb.store.request.ActivityProductSearchRequest;
import com.zbkj.crmeb.store.response.ActivityVerifyResponse;
import com.zbkj.crmeb.store.service.ActivityManageService;
import com.zbkj.crmeb.store.service.ActivityProductService;
import com.zbkj.crmeb.store.service.StoreProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * 供应商商品报名
 * @Description: 
 * @author duyb
 * @date 2022-11-10
 */
@RestController
@RequestMapping("api/admin/supplier/activity/product")
@Api(tags = "供应商商品报名")
public class SupplierProductEnrollController {
    @Autowired
    ActivityProductService activityProductService;

    @Autowired
    ActivityManageService activityManageService;

    /**
     * 列表
     * @Description:
     * @author duyb
     * @return CommonResult<Object>
     * @Date: 2022-11-10
     */
    @ApiOperation(value = "列表")
    @GetMapping("/list")
    public CommonResult<Object> listEntity() {
        return CommonResult.success(activityManageService.list(Wrappers.<ActivityManage>lambdaQuery()
                .eq(ActivityManage:: getIsShow, true)
                .and(
                        a -> a.eq(ActivityManage::getEnrollType, true)
                                .or(b -> b.lt(ActivityManage::getEnrollStartTime, new Date())
                                        .gt(ActivityManage::getEnrollEndTime, new Date())
                                ))
                .orderByAsc(ActivityManage :: getSort)
                .orderByAsc(ActivityManage :: getCreateTime)
        ));
    }


    /**
     * 报名记录分页查询
     * @Description:
     * @author duyb
     * @param @param [ActivityManageRequest pageParamRequest]
     * @return CommonResult<Object>
     * @Date: 2022-11-10
     */
    @ApiOperation(value = "报名记录分页查询")
    @GetMapping("/enroll/page")
    public CommonResult<Object> enrollPageEntity(@ModelAttribute ActivityProductSearchRequest request, @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<ActivityVerifyResponse> setUpResponseCommonPage = CommonPage.restPage(activityProductService.enrollPageEntity(request,pageParamRequest));
        return CommonResult.success(setUpResponseCommonPage);
    }

    /**
     * 通过id查询
     * @Description:
     * @author duyb
     * @param @param id
     * @return CommonResult<Object>
     * @Date: 2022-11-10
     */
    @ApiOperation(value = "通过id获取")
    @GetMapping("/{id}")
    public CommonResult<Object> getEntity(@ApiParam(value = "主键id", required = true) @PathVariable("id") Integer id) {
        return CommonResult.success(activityManageService.getEntity(id));
    }


    /**
     * 报名
     * @Description:  
     * @author duyb
     * @param @param activityProductEnrollRequest
     * @return CommonResult<Object>
     * @Date: 2022-11-10
     */
    @ApiOperation(value = "报名")
    @PostMapping("/save")
    public CommonResult<Object> save(@RequestBody ActivityProductEnrollRequest activityProductEnrollRequest) {
        return CommonResult.success(activityProductService.saveEntity(activityProductEnrollRequest));
    }

}
